package main.role;

import java.util.ArrayList;
import java.util.List;

import main.util.ArrayUtil;
import main.util.SqlConstants;

import org.apache.poi.ss.usermodel.Row;

public class Role {
	/*public static int start=10;
	public static int end=17;*/
	public static Row firstRow=null;
	
	public static String getRoleSql(Row row,String staffid,int start,int end){
		end=end+1;
		
		List<String> roles=new ArrayList<String>();
		
		if(firstRow==null){
			firstRow=row.getSheet().getRow(0);
		}
		
		for(;start<end;start++){
			String role=SqlConstants.getColValue(row, start);
			if("".equals(role)){
				continue;
			}
			
			roles.add(SqlConstants.getColValue(firstRow, start));
		}
		
		return staffrole(roles, staffid);
	}
	
	public static String staffrole(List<String> roles,String staffid){
		String sql=null;
		sql="INSERT INTO t_ucp_staffrole (`RoleId`, `staffid`) VALUES ";
		//可能有多个角色
		for(int i=0;i<roles.size();i++){
			String role=roles.get(i);
			if(role!=null && !"".equals(role)){
				role="('"+role+"', '"+staffid+"')";
				roles.set(i, role);
			}
			
		}
		
		return sql+ArrayUtil.conectArray(roles, ",")+";\n";
	}

}
